package service

import (
	"singo/model"
	"singo/serializer"
)

// MistakeDeleteService 删除错误日志的服务
type MistakeDeleteService struct {
}

// MistakeDelete 删除错误日志
func (service *MistakeDeleteService) MistakeDelete(id string) serializer.Response {
	var mistake model.Mistake
	err := model.DB.First(&mistake, "id = ?", id).Error
	if err != nil {
		return serializer.Response{
			Status: 404,
			Msg:    "错误日志不存在",
			Error:  err.Error(),
		}
	}

	err = model.DB.Delete(&mistake).Error
	if err != nil {
		return serializer.Response{
			Status: 50000,
			Msg:    "错误日志删除失败",
			Error:  err.Error(),
		}
	}

	return serializer.Response{
		Data:   true,
		Msg:    "成功",
		Status: 0,
	}
}
